﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;
using System.Windows.Forms;

namespace 学生成绩管理系统
{
    class DataAccess
    {
        private string strDSN;
        OleDbConnection oledbcon;
        public void dataCon()
        {
            strDSN = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Application.StartupPath.ToString() + "\\student.accdb";
            oledbcon = new OleDbConnection(strDSN );
        }
        public DataSet getDataset(String sql)
        {
            DataSet ds = new DataSet();
            oledbcon.Open();
            try
            {
                OleDbCommand oledbcom = new OleDbCommand(sql, oledbcon);
                OleDbDataAdapter oledbDa = new OleDbDataAdapter(oledbcom);
                oledbDa.Fill(ds);
                return ds;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
            finally { oledbcon.Close(); }
        }
        public bool sqlExec(string sql)
        {
            try { oledbcon.Open(); }
            catch { MessageBox.Show("数据库未连接"); }
            try
            {
                OleDbCommand oledbcom = new OleDbCommand();
                oledbcom.ExecuteNonQuery();
                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "提升");
                return false;
            }

            finally { oledbcon.Close(); }
        }
    }
}
